home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_server_tracking.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  7.2 KB  |  322 lines

  1. unit ntc_server_tracking;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     StdCtrls,
  36.     Buttons,
  37.     ExtCtrls,
  38.     inifiles,
  39.  
  40.     ntc_server_form;
  41.  
  42. const
  43.     default_deviation=0.1;
  44.     default_rate=60;
  45.     default_lunar_rate=57.9;
  46.  
  47. type
  48.     Tscope_tracking = class(tform)
  49.         tracking_panel: TPanel;
  50.         change_tracking_group: TGroupBox;
  51.         increase_tracking_button: TBitBtn;
  52.         preset_defaults_group: TGroupBox;
  53.         lunar_tracking_button: TBitBtn;
  54.         default_tracking_button: TBitBtn;
  55.         lunar_tracking_label: TLabel;
  56.         default_tracking_label: TLabel;
  57.         decrease_tracking_button: TBitBtn;
  58.         tracking_edit: TEdit;
  59.  
  60.         { form handling }
  61.         procedure FormCreate(
  62.             Sender: TObject);
  63.  
  64.         procedure form_close_query(
  65.                     Sender: TObject;
  66.             var CanClose: Boolean);
  67.  
  68.         { configuration }
  69.         procedure save_settings;
  70.  
  71.         procedure load_settings;
  72.  
  73.         procedure flip_buttons(
  74.             toggle:boolean);
  75.  
  76.         { events }
  77.         procedure FormShow(
  78.             Sender:TObject);
  79.  
  80.         procedure adjust;
  81.  
  82.         procedure check_activate(
  83.             Sender: TObject);
  84.  
  85.         procedure decrease_tracking_buttonClick(
  86.             Sender: TObject);
  87.  
  88.         procedure increase_tracking_buttonClick(
  89.             Sender: TObject);
  90.  
  91.         procedure lunar_tracking_buttonClick(
  92.             Sender: TObject);
  93.  
  94.         procedure default_tracking_buttonClick(
  95.             Sender: TObject);
  96.  
  97.         procedure tracking_editChange(
  98.             Sender: TObject);
  99.  
  100.     private
  101.         { Private declarations }
  102.         default_tracking_rate,
  103.         default_lunar_tracking_rate:double;
  104.         tracking_rate,
  105.         lunar_tracking_rate:double;
  106.         lunar_tracking:boolean;
  107.     public
  108.         { Public declarations }
  109.         can_track:boolean;
  110.         tracks_by:double;
  111.         { configuration }
  112.         dimensions:dimensions_record;
  113.  
  114.         { events }
  115.         procedure check_visible_and_show_hide(
  116.             sender:tobject);
  117.             
  118.         procedure hide_form;
  119.         procedure show_form;
  120.     end;
  121.  
  122. var
  123.     scope_tracking:Tscope_tracking;
  124.  
  125. implementation
  126.  
  127. uses
  128.     ntc_server_network,
  129.     ntc_server_config;
  130.  
  131. {$R *.dfm}
  132.  
  133.     { -------------
  134.         form handling
  135.         ------------- }
  136.  
  137. procedure Tscope_tracking.FormCreate(Sender: TObject);
  138. begin
  139.     default_tracking_rate:=default_rate;
  140.     tracking_rate:=default_tracking_rate;
  141.     default_lunar_tracking_rate:=default_lunar_rate;
  142.     lunar_tracking_rate:=default_lunar_tracking_rate;
  143.     tracking_edit.text:=floattostr(tracking_rate);
  144.     lunar_tracking:=false;
  145.     can_track:=false;
  146.     tracks_by:=default_deviation;
  147.     flip_buttons(false);
  148.     load_settings;
  149. end;
  150.  
  151. procedure tscope_tracking.form_close_query(
  152.             Sender: TObject;
  153.     var CanClose: Boolean);
  154. begin
  155.     canclose:=false;
  156.     visible:=false;
  157.     with dimensions do
  158.         begin
  159.             form_top:=top;
  160.             form_left:=left;
  161.         end;
  162. end;
  163.  
  164.     { ---------
  165.         utilities
  166.         --------- }
  167.  
  168. procedure Tscope_tracking.flip_buttons(
  169.     toggle:boolean);
  170. begin
  171.     if scope_config.scope_type=celestron_type then
  172.         toggle:=false;
  173.     change_tracking_group.enabled:=toggle;
  174.     preset_defaults_group.enabled:=toggle;
  175. end;
  176.  
  177.     { -------------
  178.         configuration
  179.         ------------- }
  180.  
  181. procedure tscope_tracking.load_settings;
  182. begin
  183.     ini_file:=tinifile.create(application_path+'server.ini');
  184.     with ini_file do
  185.         begin
  186.             tracks_by:=ReadFloat('tracking','tracks_by',default_deviation);
  187.             default_tracking_rate:=ReadFloat(
  188.                 'tracking','default_tracking_rate',default_rate);
  189.             default_lunar_tracking_rate:=readfloat(
  190.                 'tracking','default_lunar_tracking_rate',default_lunar_rate);
  191.             { form }
  192.             scope.get_dimensions(scope_tracking,@dimensions,'tracking',ini_file);
  193.             left:=dimensions.form_left;
  194.             top:=dimensions.form_top;
  195.             visible:=readbool('tracking','visible',false);
  196.         end;
  197.     ini_file.free;
  198. end;
  199.  
  200. procedure tscope_tracking.save_settings;
  201. begin
  202.     with ini_file do
  203.         begin
  204.             writefloat('tracking','default_tracking_rate',default_tracking_rate);
  205.             writefloat(
  206.                 'tracking','default_lunar_tracking_rate',default_lunar_tracking_rate);
  207.             writefloat('tracking','tracks_by',tracks_by);
  208.             { form }
  209.             scope.find_vdu(scope_tracking,@dimensions);
  210.             scope.write_dimensions(@dimensions,left,top,'tracking',ini_file);
  211.             writebool('tracking','visible',visible);
  212.         end;
  213. end;
  214.  
  215.     { ------
  216.         events
  217.         ------ }
  218.  
  219. procedure tscope_tracking.FormShow(
  220.     Sender:TObject);
  221. begin
  222.     with dimensions do
  223.         begin
  224.             top:=form_top;
  225.             left:=form_left;
  226.         end;
  227. end;
  228.  
  229. procedure tscope_tracking.adjust;
  230. begin
  231.     with dimensions do
  232.         begin
  233.             form_top:=trunc(form_top/last_screen_height*current_height);
  234.             form_left:=trunc(form_left/last_screen_width*current_width);
  235.         end;
  236.     if visible then
  237.         show;
  238. end;
  239.  
  240. procedure tscope_tracking.check_visible_and_show_hide(
  241.     sender:tobject);
  242. begin
  243.     if visible then
  244.         hide_form
  245.     else
  246.         show_form;
  247.     scope.show_hide(sender,visible);
  248. end;
  249.  
  250. procedure tscope_tracking.hide_form;
  251. begin
  252.     with dimensions do
  253.         begin
  254.             form_top:=top;
  255.             form_left:=left;
  256.         end;
  257.     Visible:=false;
  258. end;
  259.  
  260. procedure tscope_tracking.show_form;
  261. begin
  262.     Visible:=true;
  263. end;
  264.  
  265. procedure Tscope_tracking.check_activate(
  266.     Sender: TObject);
  267. begin
  268.     scope.form_activate(scope_tracking,@dimensions);
  269. end;
  270.  
  271. procedure Tscope_tracking.decrease_tracking_buttonClick(
  272.     Sender: TObject);
  273. begin
  274.     if scope_network.local_scope_control and
  275.          (scope_network.send_message_check('decrease_tracking')>=[exit_ok]) then
  276.         begin
  277.             tracking_rate:=tracking_rate-default_deviation;
  278.             tracking_edit.text:=floattostr(tracking_rate);
  279.         end;
  280. end;
  281.  
  282. procedure Tscope_tracking.increase_tracking_buttonClick(
  283.     Sender: TObject);
  284. begin
  285.     if scope_network.local_scope_control and
  286.          (scope_network.send_message_check('increase_tracking')>=[exit_ok]) then
  287.         begin
  288.             tracking_rate:=tracking_rate+default_deviation;
  289.             tracking_edit.text:=floattostr(tracking_rate);
  290.         end;
  291. end;
  292.  
  293. procedure Tscope_tracking.lunar_tracking_buttonClick(
  294.     Sender: TObject);
  295. begin
  296.     if scope_network.local_scope_control then
  297.         begin
  298.             scope_network.send_message_check('lunar_tracking');
  299.             tracking_rate:=default_lunar_tracking_rate;
  300.             tracking_edit.text:=floattostr(tracking_rate);
  301.         end;
  302. end;
  303.  
  304. procedure Tscope_tracking.default_tracking_buttonClick(
  305.     Sender: TObject);
  306. begin
  307.     if scope_network.local_scope_control then
  308.         begin
  309.             scope_network.send_message_check('default_tracking');
  310.             tracking_rate:=default_tracking_rate;
  311.             tracking_edit.text:=floattostr(tracking_rate);
  312.         end;
  313. end;
  314.  
  315. procedure Tscope_tracking.tracking_editChange(
  316.     Sender: TObject);
  317. begin
  318.     tracking_edit.text:=floattostr(tracking_rate);
  319. end;
  320.  
  321. end.
  322.